package com.github.shuaidd.rest.runtime;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.shuaidd.service.runtime.LwfActivitiTaskActionService;
import lombok.RequiredArgsConstructor;
import org.activiti.app.model.runtime.TaskRepresentation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("app")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class TaskActionResource {

    private final LwfActivitiTaskActionService taskActionService;

    @RequestMapping(value = "/rest/tasks/{taskId}/action/complete", method = RequestMethod.PUT)
    @ResponseStatus(value = HttpStatus.OK)
    public void completeTask(@PathVariable String taskId) {
        taskActionService.completeTask(taskId);
    }

    @RequestMapping(value = "/rest/tasks/{taskId}/action/assign", method = RequestMethod.PUT)
    public TaskRepresentation assignTask(@PathVariable String taskId, @RequestBody ObjectNode requestNode) {
        return taskActionService.assignTask(taskId, requestNode);
    }

    @RequestMapping(value = "/rest/tasks/{taskId}/action/involve", method = RequestMethod.PUT, produces = "application/json")
    @ResponseStatus(value = HttpStatus.OK)
    public void involveUser(@PathVariable("taskId") String taskId, @RequestBody ObjectNode requestNode) {
        taskActionService.involveUser(taskId, requestNode);
    }

    @RequestMapping(value = "/rest/tasks/{taskId}/action/remove-involved", method = RequestMethod.PUT, produces = "application/json")
    @ResponseStatus(value = HttpStatus.OK)
    public void removeInvolvedUser(@PathVariable("taskId") String taskId, @RequestBody ObjectNode requestNode) {
        taskActionService.removeInvolvedUser(taskId, requestNode);
    }

    @RequestMapping(value = "/rest/tasks/{taskId}/action/claim", method = RequestMethod.PUT)
    @ResponseStatus(value = HttpStatus.OK)
    public void claimTask(@PathVariable String taskId) {
        taskActionService.claimTask(taskId);
    }

}
